package com.whpost.service.dao.addr;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whpost.service.entity.addr.TWxAddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yinzhuoyi
 * @since 2020-05-21
 */
@Mapper
public interface TWxAddressBookDao extends BaseMapper<TWxAddressBook> {


    @Select("select * from t_wx_address_book where ${ew.sqlSegment} ")
    @Results(id="addressBookMap",value = {
            @Result(column="province_lsh",property="tWxProvince",
                    one=@One(
                            select="com.whpost.service.dao.addr.TWxAddrDao.getProv")
            ),
            @Result(column="city_lsh",property="tWxCity",
                    one=@One(
                            select="com.whpost.service.dao.addr.TWxAddrDao.getCity")
            ),
            @Result(column="county_lsh",property="tWxCounty",
                    one=@One(
                            select="com.whpost.service.dao.addr.TWxAddrDao.getCounty")
            )
    })
    List<TWxAddressBook> getTWxAddressBookL(@Param("ew") QueryWrapper wrapper);

    @Select("select * from t_wx_address_book where ${ew.sqlSegment} ")
    @ResultMap(value="addressBookMap")
    TWxAddressBook getTWxAddressBook(@Param("ew") QueryWrapper wrapper);

    @Select("select * from t_wx_address_book where lsh=#{0}")
    @ResultMap(value="addressBookMap")
    TWxAddressBook getTWxAddressBookById(Long lsh);

    @Select("select * from t_wx_address_book where ${ew.sqlSegment} ")
    @ResultMap(value="addressBookMap")
    IPage<TWxAddressBook> getTWxAddressBookLPage(Page<TWxAddressBook> page, @Param("ew") QueryWrapper wrapper);

    @Update("update t_wx_address_book set is_default ='0' where hyxx_lsh=#{lsh} and addr_type=#{lx}")
    int updateDefault(Long lsh, String lx);

    @Update("update t_wx_address_book set is_default =#{bz} where lsh=#{clsh} and hyxx_lsh=#{lsh}")
    int setDefault(String bz, String clsh, String lsh);

    @Select("select id from t_wx_address_book where tel_jsm LIKE CONCAT('%', #{cxtj}, '%') or name LIKE CONCAT('%', #{cxtj}, '%') or address LIKE CONCAT('%', #{cxtj}, '%')")
    List<String> getIdList(String cxtj);
}
